{% extends "appbuilder/general/model/show.html" %}

{% block content %}
{{ super() }}

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">批量模型依赖关系图</h3>
    </div>
    <div class="panel-body">
        <div class="row">
            <div class="col-md-3">
                <h4>选中的模型:</h4>
                <ul class="list-group">
                    {% for model in models %}
                    <li class="list-group-item">
                        <strong>{{ model.name }}</strong>
                        <br><small>版本: {{ model.version }}</small>
                    </li>
                    {% endfor %}
                </ul>
            </div>
            <div class="col-md-9">
                <div id="batch-dependency-graph" data-model-ids="{{ model_ids }}"></div>
            </div>
        </div>
    </div>
</div>

<script>
$(document).ready(function() {
    const modelIds = $('#batch-dependency-graph').data('model-ids');
    
    fetch(`/model_visualization/api/batch_dependency_graph/${modelIds}`)
        .then(response => response.json())
        .then(data => {
            renderBatchDependencyGraph(data.data, '#batch-dependency-graph');
        })
        .catch(error => {
            console.error('加载批量依赖关系图失败:', error);
            $('#batch-dependency-graph').html('<p class="text-danger">加载依赖关系图失败</p>');
        });
});

function renderBatchDependencyGraph(data, selector) {
    // 实现批量依赖关系图的可视化
    const container = d3.select(selector);
    container.html('');
    
    const svg = container.append('svg')
        .attr('width', 700)
        .attr('height', 500);
    
    // 使用力导向图显示多个模型的依赖关系
    // 具体实现根据数据结构调整
}
</script>
{% endblock %}